if (typeof ace == "undefined" && typeof require == "undefined") {
    document.body.innerHTML = "<p style='padding: 20px 50px;'>couldn't find ace.js file, <br>"
        + "to build it run <code>node Makefile.dryice.js full<code>"
} else if (typeof ace == "undefined" && typeof require != "undefined") {
    require(["ace/ace"], setValue)
} else {
    require = ace.require;
    setValue()
}

function setValue() {


    var t = "package com.mico.examplet.springboot.webshell.config;\n" +
        "\n" +
        "import com.mico.examplet.springboot.webshell.handler.Server;\n" +
        "import com.mico.examplet.springboot.webshell.handler.ShellClient;\n" +
        "import com.mico.examplet.springboot.webshell.handler.WebsocketUtil;\n" +
        "import org.springframework.stereotype.Component;\n" +
        "import org.springframework.web.socket.TextMessage;\n" +
        "\n" +
        "import javax.websocket.*;\n" +
        "import javax.websocket.server.ServerEndpoint;\n" +
        "import java.io.IOException;\n" +
        "import java.net.InetSocketAddress;\n" +
        "import java.util.Arrays;\n" +
        "import java.util.concurrent.CopyOnWriteArraySet;\n" +
        "\n" +
        "@ServerEndpoint(value = \"/web_shell\")\n" +
        "@Component\n" +
        "public class WebSocket {\n" +
        "    //静态变量，用来记录当前在线连接数。应该把它设计成线程安全的。\n" +
        "    private static int onlineCount = 0;\n" +
        "\n" +
        "    //concurrent包的线程安全Set，用来存放每个客户端对应的MyWebSocket对象。\n" +
        "    private static CopyOnWriteArraySet<WebSocket> webSocketSet = new CopyOnWriteArraySet<WebSocket>();\n" +
        "\n" +
        "    //与某个客户端的连接会话，需要通过它来给客户端发送数据\n" +
        "    private Session session;\n" +
        "\n" +
        "\n" +
        "\n" +
        "    //客户端\n" +
        "    ShellClient client = null;\n" +
        "\n" +
        "    /**\n" +
        "     * 连接建立成功调用的方法*/\n" +
        "    @OnOpen\n" +
        "    public void onOpen(Session session) {\n" +
        "        this.session = session;\n" +
        "        webSocketSet.add(this);     //加入set中\n" +
        "        InetSocketAddress remoteAddress = WebsocketUtil.getRemoteAddress(session);\n" +
        "        System.out.println(\"有新连接加入！ip 为:\"+remoteAddress.getAddress().getHostAddress()+\",当前在线人数为\" + webSocketSet.size());\n" +
        "        //做多个用户处理的时候，可以在这个地方来 ,判断用户id和\n" +
        "        //配置服务器信息\n" +
        "        Server server = new Server(\"192.168.1.104\",\"root\",\"mico\");\n" +
        "\n" +
        "        //初始化客户端\n" +
        "        client = new ShellClient(server, session);\n" +
        "\n" +
        "        //连接服务器\n" +
        "        client.connect();\n" +
        "    }\n" +
        "\n" +
        "    /**\n" +
        "     * 连接关闭调用的方法\n" +
        "     */\n" +
        "    @OnClose\n" +
        "    public void onClose() {\n" +
        "        webSocketSet.remove(this);  //从set中删除\n" +
        "        //关闭连接\n" +
        "        if (client != null) {\n" +
        "            System.out.println(\"有连接关闭，关闭其ssh连接\");\n" +
        "            client.disconnect();\n" +
        "        }\n" +
        "    }\n" +
        "\n" +
        "    /**\n" +
        "     * 收到客户端消息后调用的方法\n" +
        "     *\n" +
        "     * @param msg 客户端发送过来的消息*/\n" +
        "    @OnMessage\n" +
        "    public void onMessage(String msg, Session session) {\n" +
        "        System.out.println(\"来自客户端的消息:\" + msg);\n" +
        "\n" +
        "        //处理连接\n" +
        "        try {\n" +
        "            //当客户端不为空的情况\n" +
        "            if (client != null) {\n" +
        "                //receive a close cmd ?\n" +
        "                if (Arrays.equals(\"exit\".getBytes(), msg.getBytes())) {\n" +
        "\n" +
        "                    if (client != null) {\n" +
        "                        client.disconnect();\n" +
        "                    }\n" +
        "\n" +
        "                    session.close();\n" +
        "                    return ;\n" +
        "                }\n" +
        "                //写入前台传递过来的命令，发送到目标服务器上\n" +
        "                client.write(new String(msg.getBytes(), \"UTF-8\"));\n" +
        "            }\n" +
        "        } catch (Exception e) {\n" +
        "            e.printStackTrace();\n" +
        "            try {\n" +
        "                session.getBasicRemote().sendText(\"An error occured, websocket is closed.\");\n" +
        "                session.close();\n" +
        "            } catch (IOException e1) {\n" +
        "                e1.printStackTrace();\n" +
        "            }\n" +
        "        }\n" +
        "    }\n" +
        "\n" +
        "    /**\n" +
        "     * 发生错误时调用\n" +
        "     */\n" +
        "    @OnError\n" +
        "    public void onError(Session session, Throwable error) {\n" +
        "        System.out.println(\"发生错误\");\n" +
        "        error.printStackTrace();\n" +
        "    }\n" +
        "\n" +
        "\n" +
        "    public void sendMessage(String message) throws IOException {\n" +
        "        this.session.getBasicRemote().sendText(message);\n" +
        "        //this.session.getAsyncRemote().sendText(message);\n" +
        "    }\n" +
        "\n" +
        "\n" +
        "    /**\n" +
        "     * 群发自定义消息\n" +
        "     * */\n" +
        "    public static void sendInfo(String message) throws IOException {\n" +
        "        for (WebSocket item : webSocketSet) {\n" +
        "            try {\n" +
        "                item.sendMessage(message);\n" +
        "            } catch (IOException e) {\n" +
        "                continue;\n" +
        "            }\n" +
        "        }\n" +
        "    }\n" +
        "\n" +
        "}"

        var el = document.getElementById("editor");
        el.env.editor.setValue(t, 1);
}